﻿package frEngine.render
{
    import __AS3__.vec.*;
    import baseEngine.core.*;
    import baseEngine.system.*;
    import flash.display3D.*;
    import frEngine.core.*;
    import frEngine.primitives.*;
    import frEngine.shader.*;
    import frEngine.shader.filters.*;
    import frEngine.shader.filters.fragmentFilters.*;
    import frEngine.shader.filters.vertexFilters.*;
    import frEngine.shader.registType.*;

    public class CylinderRender extends DefaultRender
    {
        private var depthColorRegister:FcParam;
        private var cylinderVertexFilter:CylinderAnimaterVertexFilter;
        private var cylinderDepthMaterial:ShaderBase;
        private var cylinderParams:Vector.<Number>;
        public static const instance:CylinderRender = new CylinderRender;

        public function CylinderRender()
        {
            this.cylinderVertexFilter = new CylinderAnimaterVertexFilter(10, 10, 10);
            this.cylinderDepthMaterial = new ShaderBase("CylinderRender", this.cylinderVertexFilter, new ColorFilter(0, 0, 0, 1));
            this.cylinderParams = this.cylinderVertexFilter.params;
            return;
        }// end function

        override public function drawDepth(param1:Mesh3D, param2:Number = 1, param3:Number = 1, param4:Number = 1, param5:Number = 1) : void
        {
            var _loc_6:FrSurface3D = null;
            var _loc_7:Boolean = false;
            var _loc_8:Boolean = false;
            var _loc_9:FrAnimCylinder = null;
            var _loc_10:MaterialParams = null;
            _loc_6 = param1.getSurface(0);
            if (_loc_6 && _loc_6.visible)
            {
                _loc_7 = this.cylinderDepthMaterial.materialParams.needRebuild;
                _loc_8 = this.cylinderDepthMaterial.hasPrepared(param1, _loc_6);
                if (!this.depthColorRegister || _loc_7)
                {
                    this.depthColorRegister = this.cylinderDepthMaterial.getParam(FilterName.COLOR, false);
                }
                if (!_loc_8)
                {
                    return;
                }
                _loc_9 = FrAnimCylinder(param1);
                this.cylinderParams[0] = _loc_9.topR;
                this.cylinderParams[1] = _loc_9.height;
                this.cylinderParams[2] = _loc_9.bottomR;
                Device3D.global.copyFrom(param1.world);
                var _loc_11:* = Global3D;
                var _loc_12:* = Global3D.objectsDrawn + 1;
                _loc_11.objectsDrawn = _loc_12;
                if (this.depthColorRegister)
                {
                    this.depthColorRegister.value[0] = param2;
                    this.depthColorRegister.value[1] = param3;
                    this.depthColorRegister.value[2] = param4;
                    this.depthColorRegister.value[3] = param5;
                    _loc_10 = param1.material.materialParams;
                    this.cylinderDepthMaterial.draw(param1, _loc_6, _loc_10.depthCompare, _loc_10.cullFace, true, Context3DBlendFactor.SOURCE_ALPHA, Context3DBlendFactor.ONE_MINUS_SOURCE_ALPHA, _loc_6.firstIndex, _loc_6.indexBufferFr.numTriangles);
                }
            }
            return;
        }// end function

    }
}
